﻿#ifndef UDPSOCKETNETWORKCENTER_H
#define UDPSOCKETNETWORKCENTER_H

#include <QMutex>
#include <QThread>
#include <QUdpSocket>

class UdpSocketNetWorkCenter : public QThread
{
    Q_OBJECT
public:
    /**
    * 获取单例实例
    * @return 返回单例实例
    */
    static UdpSocketNetWorkCenter* getInstance();
    /**
    * 删除单例实例
    */
    static void deleteInstance();
    /**
     * @brief sendMessage 发送消息
     * @param channel
     * @param message
     */
    void sendMessage(QString &message);
private:
    explicit UdpSocketNetWorkCenter(QObject *parent = nullptr);
    ~UdpSocketNetWorkCenter();
    quint16 getSendPackId();
private:
    static UdpSocketNetWorkCenter* instance;
    static QMutex mutex;
signals:
    void signal_send_message(QString &message);
private slots:
    void slot_send_message(QString &message);
private:
    QUdpSocket *m_socket;
    quint16 sendPackId;

    QString broadcastAddress;
    quint16 broadcastPort;
    quint16 bindProt;
protected:
    void run() override;

};

#endif // UDPSOCKETNETWORKCENTER_H
